﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：新增表单
 */

var keyValue = request('keyValue');
var userdefault = {};
var bootstrap = function ($, learun) {
    "use strict";

    var companyId = '';

    var page = {
        init: function () {
            userdefault = learun.clientdata.get(['userinfo']);
            page.bind();
            page.initData();
        },
        bind: function () {
            // 优化滚动条
            $('.lr-layout-wrap').lrscroll();

            // 订单产品信息
            $('#productgird').jfGrid({
                headData: [
                    {
                        label: "模型信息", name: "a1", width: 80, align: "center", frozen: true,
                        children: [
                            {label: '模型id', name: 'modelId', width: 80, align: 'center'},
                            {label: '模型名称', name: 'modelName', width: 360, align: 'left'}
                        ]
                    },
                    {label: '结果文件url', name: 'resultUrl', width: 300, align: 'left'},
                    {
                          label: "操作", name: "btn2", width: 180, align: "center",
                          formatter: function (value, row, op, $cell) {
                              $cell.on('click', '.previewResult', function () {
                                  if ($cell.html().trim() == '') {
                                      return false;
                                  }
                                  var code = row.modelId;
                                  var keyValue = row.modelId;
                                  var modelName = row.modelName;
                                  if (learun.checkrow(keyValue)) {
                                      learun.layerForm({
                                          id: 'preview_result' + keyValue,
                                          title: '预览结果集',
                                          url: config.webportal_server + 'pages/finance/audit_rule/preview_result/result' + code + '.html?modelId=' + keyValue + '&access_token=' + config.getToken().access_token,
                                          width: 1000,
                                          height: 800,
                                          maxmin: true,
                                          btn: null
                                      });
                                  }
                                  return false;
                              });
                                  return '<span class="label label-info previewResult" style="cursor: pointer;">预览</span>';
                          }
                    },
                ],
                isEdit: false,
                height: 300,
                isMultiselect: false
            });


            //初始化默认值
            var loginInfo = learun.clientdata.get(['userinfo']);
            $("#createUsername").val(loginInfo.user.realName);
            $("#createTime").val(new Date().format("yyyy-MM-dd"));
        },
        initData: function () {
            if (!!keyValue) {
                $.lrSetForm(config.base_server() + 'auditmodelwarnplans/findById?id=' + keyValue + '&access_token=' + config.getToken().access_token, function (data) {
                    $('.lr-layout-wrap').lrSetFormData(data);
                    //$("#departmentId").lrselectSet(data.departmentId);
                    $('#productgird').jfGridSet('refreshdata', data.detailList);
                });
            } else {
                $("#print").hide();
                $('#productgird').jfGridSet('addRow', {});
            }
        }
    };

    page.init();
}
